package cn.zcscloud.mall.service.impl;

import cn.zcscloud.mall.mbg.mapper.SmsHomeRecommendProductMapper;
import cn.zcscloud.mall.mbg.model.SmsHomeRecommendProduct;
import cn.zcscloud.mall.service.SmsHomeRecommendProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class SmsHomeRecommendProductServiceImpl extends ServiceImpl<SmsHomeRecommendProductMapper, SmsHomeRecommendProduct> implements SmsHomeRecommendProductService {
    @Override
    public int saveList(List<SmsHomeRecommendProduct> homeRecommendProductList) {
        int count= 0;
        for (SmsHomeRecommendProduct smsHomeRecommendProduct : homeRecommendProductList) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("product_id",smsHomeRecommendProduct.getProductId());
            List<SmsHomeRecommendProduct> smsHomeRecommendProducts = this.listByMap(map);
            if (!smsHomeRecommendProducts.isEmpty()) continue;
            this.save(smsHomeRecommendProduct);
            count++;
        }
        return count;
    }
}
